import { Controller, Get, Post, Put, Delete, Body, Param, Query } from '@nestjs/common';
import { TemplateService } from './template.service';
import { CreateTemplateDto, UpdateTemplateDto } from './template.dto';
import { ApiTags, ApiOperation, ApiResponse, ApiQuery } from '@nestjs/swagger';

@ApiTags('templates')
@Controller('templates')
export class TemplateController {
    constructor(private readonly templateService: TemplateService) { }

    @ApiOperation({ summary: '获取模板列表' })
    @ApiQuery({ name: 'page', required: false, type: Number })
    @ApiQuery({ name: 'limit', required: false, type: Number })
    @ApiQuery({ name: 'category', required: false, type: String })
    @ApiQuery({ name: 'search', required: false, type: String })
    @ApiResponse({ status: 200, description: '成功获取模板列表' })
    @Get()
    async findAll(@Query() query: any) {
        return this.templateService.findAll(query)
    }

    @ApiOperation({ summary: '获取单个模板' })
    @ApiResponse({ status: 200, description: '成功获取模板详情' })
    @ApiResponse({ status: 404, description: '模板不存在' })
    @Get(':id')
    async findOne(@Param('id') id: string) {
        return this.templateService.findOne(id)
    }

    @ApiOperation({ summary: '创建模板' })
    @ApiResponse({ status: 201, description: '成功创建模板' })
    @Post()
    async create(@Body() createTemplateDto: CreateTemplateDto) {
        return this.templateService.create(createTemplateDto)
    }

    @ApiOperation({ summary: '更新模板' })
    @ApiResponse({ status: 200, description: '成功更新模板' })
    @ApiResponse({ status: 404, description: '模板不存在' })
    @Put(':id')
    async update(@Param('id') id: string, @Body() updateTemplateDto: UpdateTemplateDto) {
        return this.templateService.update(id, updateTemplateDto)
    }

    @ApiOperation({ summary: '删除模板' })
    @ApiResponse({ status: 200, description: '成功删除模板' })
    @ApiResponse({ status: 404, description: '模板不存在' })
    @Delete(':id')
    async remove(@Param('id') id: string) {
        return this.templateService.remove(id)
    }
}